package Commons;


import java.util.ArrayList;
import java.io.*;

public class Config {

    public static boolean checkBit(int data, int position) {
        int buf = 1;
        buf = (buf << position);
        return ((buf & data) > 0);
    }

    public static void loadMemory(ArrayList<Cell> mem, String file) throws IOException {
        BufferedReader reader = new BufferedReader(new FileReader(new File(file)));
        int j = 0;
        try {
            for (int i = 0; i < mem.size(); i++) {
                mem.get(i).set(Integer.parseInt(reader.readLine().split(" ")[1], 16));
                j++;
            }
        } catch (IOException e) {
            for (; j < mem.size(); j++) {
                mem.get(j).set(0);
            }
        }
    }

    public static void storeMemory(ArrayList<Cell> mem, String file) throws IOException {
        BufferedWriter reader = new BufferedWriter(new FileWriter(new File(file)));
        for (int i = 0; i < mem.size(); i++) {
            String buf = Integer.toHexString(i) + " " + Integer.toHexString(mem.get(i).onlyGet());
        }
    }
}
